package com.ultrapower.bean;

import java.util.ArrayList;
import java.util.List;

import com.ultrapower.buffer.Buffer;
import com.ultrapower.buffer.FixedBuffer;

public class ServerMetaDataBean {
	private final String serverInfo;
	private final List<String> vmArgs;
	private final List<ServiceInfoBean> serviceInfos;

	public ServerMetaDataBean(final byte[] value) {
		final Buffer buffer = new FixedBuffer(value);
		this.serverInfo = buffer.read2PrefixedString();
		final int numVmArgs = buffer.readVInt();
		this.vmArgs = new ArrayList<String>(numVmArgs);
		for (int i = 0; i < numVmArgs; i++) {
			this.vmArgs.add(buffer.read2PrefixedString());
		}
		final int numServiceInfos = buffer.readVInt();
		this.serviceInfos = new ArrayList<ServiceInfoBean>(numServiceInfos);
		for (int i = 0; i < numServiceInfos; i++) {
			ServiceInfoBean serviceInfoBo = new ServiceInfoBean(buffer.readPrefixedBytes());
			this.serviceInfos.add(serviceInfoBo);
		}
	}

	@Override
	public String toString() {
		return "ServerMetaDataBean [serverInfo=" + serverInfo + ", vmArgs=" + vmArgs + ", serviceInfos=" + serviceInfos
				+ "]";
	}

}
